package com.zuozuo.reflection;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;

public class Demo5 {
    public static void test1(Map<String,User> map){

    }

    public static Map<String,User> test2(){
        return null;
    }

    public static void main(String[] args) throws Exception{
        Class c1 = Class.forName("com.zuozuo.reflection.Demo5");
        Method test1 = c1.getMethod("test1", Map.class);
        Type[] genericParameterTypes = test1.getGenericParameterTypes();
        for (Type genericParameterType : genericParameterTypes) {
            System.out.println(genericParameterType);
            if(genericParameterType instanceof ParameterizedType) {
                Type[] actualTypeArguments = ((ParameterizedType) genericParameterType).getActualTypeArguments();
                for (Type actualTypeArgument : actualTypeArguments) {

                    System.out.println(actualTypeArgument);
                }
            }
        }
        Method test2 = c1.getMethod("test2", null);
        Type genericReturnType = test2.getGenericReturnType();
        System.out.println(genericReturnType);
        if(genericReturnType instanceof ParameterizedType){
            Type[] actualTypeArguments = ((ParameterizedType) genericReturnType).getActualTypeArguments();
            for (Type actualTypeArgument : actualTypeArguments) {
                System.out.println(actualTypeArgument);
            }
        }
    }


}

